package com.jaya.budan.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.google.gson.Gson;
import com.jaya.budan.R;
import com.jaya.budan.base.BaseActivity;
import com.jaya.budan.connect.RequestConnect;
import com.jaya.budan.utils.ToolUtils;
import com.jaya.budan.utils.VolleyUtil;
import com.jaya.budan.views.CommonPopWindow;

import org.json.JSONException;
import org.json.JSONObject;

public class TaRen_Set_Report_Detail2_Activity extends BaseActivity implements View.OnClickListener, CommonPopWindow.ViewClickListener {

    private RelativeLayout back;
    private Button btn_login;
    private String access_token, uid;
    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_taren_set_report_detail2);
        Intent intent = getIntent();
        access_token = intent.getStringExtra("access_token");
        uid = intent.getStringExtra("uid");
        back = findViewById(R.id.back);
        btn_login = findViewById(R.id.btn_login);
        back.setOnClickListener(this);
        btn_login.setOnClickListener(this);
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            case R.id.btn_login:
                Intent intent = new Intent(TaRen_Set_Report_Detail2_Activity.this, TaRen_Main_Activity.class);
                intent.putExtra("access_token", access_token);
                intent.putExtra("uid", uid);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                if (TaRen_Main_Activity.activity != null){
                    TaRen_Main_Activity.activity.finish();
                }
                if (Chat_Activity.activity != null){
                    Chat_Activity.activity.finish();
                }
                if (Chat_Msg_Set_Activity.activity != null){
                    Chat_Msg_Set_Activity.activity.finish();
                }
                if (TaRen_Set_Report_Activity.activity != null){
                    TaRen_Set_Report_Activity.activity.finish();
                }
                if (TaRen_Set_Report_Reason_Activity.activity != null){
                    TaRen_Set_Report_Reason_Activity.activity.finish();
                }
                break;
            default:
                break;
        }
    }

    /**
     * 网络请求
     */
    private void postData(View view) {
        JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, RequestConnect.User_Choose_information_Url + access_token + "&client=1", null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject jsonObject) {
                Log.d("tiaojian", jsonObject.toString());
                try {
                    int code = jsonObject.optInt("code");
                    int status = jsonObject.optInt("status");
                    String message = jsonObject.getString("message");
                    if (code == 0) {
                        Gson gson = new Gson();
                        JSONObject info = jsonObject.getJSONObject("info");
                        CommonPopWindow.newBuilder()
                                .setView(R.layout.pop_geren_fans_cancle)
                                .setAnimationStyle(R.style.AnimUp)
                                .setBackgroundDrawable(new BitmapDrawable())
                                .setSize(0, 600)
                                .setViewOnClickListener(TaRen_Set_Report_Detail2_Activity.this)
                                .setBackgroundDarkEnable(true)
                                .setBackgroundAlpha(0.7f)
                                .build(TaRen_Set_Report_Detail2_Activity.this)
                                .showAsCenter(view);
                    } else {
                        ToolUtils.showToast(TaRen_Set_Report_Detail2_Activity.this, message);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                ToolUtils.showToast(TaRen_Set_Report_Detail2_Activity.this, "网络请求失败，请稍后重试~");
            }
        });
        request.setTag(this);
        VolleyUtil.getQueue(this).add(request);
    }

    @SuppressLint({"NonConstantResourceId", "SetTextI18n"})
    @Override
    public void getChildView(final PopupWindow mPopupWindow, View view, int mLayoutResId) {
        switch (mLayoutResId) {
            case R.layout.pop_geren_fans_cancle:
                TextView tv_cancle = view.findViewById(R.id.tv_cancle);
                TextView tv_geren_fans_cancle = view.findViewById(R.id.tv_geren_fans_cancle);
                TextView img_guanbi = view.findViewById(R.id.img_guanbi);
                tv_geren_fans_cancle.setText("举报已提交审核，感谢您对平台的支持");
                tv_cancle.setVisibility(View.GONE);
                img_guanbi.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mPopupWindow.dismiss();
                    }
                });
                break;
            default:
                break;
        }
    }
}
